package com.qijian.maindata.domain.query;

import com.baomidou.mybatisplus.annotation.TableName;
import com.qijian.common.utils.mybatis.WhereType;
import com.qijian.common.utils.mybatis.WhereTypeEnum;
import lombok.Data;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Set;


/**
 * 工序工单对象 查询条件类
 *
 * @author qijian
 * @date 2021-10-09
 */

@Data
@ToString
@TableName("main_process_order")
public class ProcessOrderQuery {

    @WhereType(filed = "work_id")
    private Long workId;
    @WhereType(filed = "project_id")
    private Long projectId;
    @WhereType(filed = "project_id", type = WhereTypeEnum.IN)
    private Set<Long> projectIds;
    @WhereType(filed = "project_id", type = WhereTypeEnum.IN)
    private List<Long> projectIdList;
    @WhereType(filed = "user_id")
    private Long userId;
    @WhereType(filed = "factory_id")
    private Long factoryId;
    @WhereType(filed = "source_id")
    private String sourceId;
    @WhereType(filed = "work_code", type = WhereTypeEnum.LIKE)
    private String workCode;
    @WhereType(filed = "ncr_code")
    private String ncrCode;
    @WhereType(filed = "work_type")
    private String workType;
    @WhereType(filed = "item_id")
    private Long itemId;
    @WhereType(filed = "item_name", type = WhereTypeEnum.LIKE)
    private String itemName;

    @WhereType(filed = "item_name", tableName = "main_item", type = WhereTypeEnum.LIKE)
    private String itemNamePG;
    @WhereType(filed = "process_id")
    private Long processId;
    @WhereType(filed = "process_id", type = WhereTypeEnum.NOTNULL)
    private Boolean processIdIsNotNull;
    @WhereType(filed = "process_id", type = WhereTypeEnum.IN)
    private List<Long> processIds;
    @WhereType(filed = "process_name", type = WhereTypeEnum.LIKE)
    private String processName;
    @WhereType(filed = "work_number")
    private Long workNumber;
    @WhereType(filed = "work_time")
    private BigDecimal workTime;
    @WhereType(filed = "work_cost")
    private BigDecimal workCost;
    @WhereType(filed = "work_start_time", type = WhereTypeEnum.GE)
    private Date workStartTime;
    @WhereType(filed = "work_end_time", type = WhereTypeEnum.LE)
    private String workEndTime;
    @WhereType(filed = "is_out")
    private Boolean isOut;
    @WhereType(filed = "is_close")
    private Boolean isClose;
    @WhereType(filed = "status", type = WhereTypeEnum.IN)
    private List<Integer> status;
    @WhereType(filed = "status")
    private Integer statusEq;
    @WhereType(filed = "status", type = WhereTypeEnum.NOTIN)
    private List<Integer> statusNot;
    @WhereType(filed = "status", tableName = "main_process_order_users")
    private Integer wuStatus;
    @WhereType(filed = "status", tableName = "main_process_order_users", type = WhereTypeEnum.NEQ)
    private Integer wuStatusNot;
    @WhereType(filed = "work_id", type = WhereTypeEnum.IN)
    private Set<Long> ids;
    @WhereType(filed = "work_id", type = WhereTypeEnum.NOTIN)
    private List<Long> workIdsNot;
    @WhereType(filed = "project_no", tableName = "main_project", type = WhereTypeEnum.LIKE)
    private String projectNo;
    @WhereType(filed = "project_no", tableName = "main_project")
    private String projectNoEq;
    @WhereType(filed = "status", tableName = "main_project", type = WhereTypeEnum.NOTIN)
    private List<Integer> projectStatusNot;
    @WhereType(filed = "project_name", tableName = "main_project", type = WhereTypeEnum.LIKE)
    private String projectName;
    @WhereType(filed = "drawing_no", tableName = "main_item", type = WhereTypeEnum.LIKE)
    private String drawingNo;
    @WhereType(filed = "part_no", tableName = "main_item", type = WhereTypeEnum.LIKE)
    private String partNo;
    @WhereType(filed = "nick_name", type = WhereTypeEnum.LIKE)
    private String nickName;
    @WhereType(filed = "machine_no", tableName = "main_project")
    private String machineNo;
    @WhereType(filed = "plan_system", tableName = "main_line_process")
    private String planSystem;
    @WhereType(filed = "bom_id", tableName = "main_project")
    private Long bomId;
    @WhereType(filed = "check_time", tableName = "main_process_order_users", type = WhereTypeEnum.BETWEEN)
    private List<String> checkTime;
    @WhereType(filed = "check_time", tableName = "main_process_order_users", type = WhereTypeEnum.LT)
    private Date checkTimeLt;
    @WhereType(filed = "user_id", tableName = "main_process_order_users")
    private Long wuUserId;

    @WhereType(filed = "nick_name", tableName = "main_process_order_users", type = WhereTypeEnum.LIKE)
    private String wuUserName;

    private String name;

    @WhereType(filed = "user_id", tableName = "main_process_order_users", type = WhereTypeEnum.GT)
    private Long wuUserIdGT;

    @WhereType(func = "main_process_order.work_end_time<main_process_order.update_time and main_process_order.work_end_time < now()")
    private Boolean isEndTime;

    @WhereType(deptTableName = "main_process_order", userTableName = "main_process_order")
    private Boolean dataScope;

    @WhereType
    private Long factoryScope;

    @WhereType(filed = "is_support", tableName = "main_process_order_users")
    private Boolean isSupport;

    @WhereType(filed = "assigned_cost", func = "IFNULL(assigned_cost,0) >0")
    private BigDecimal assignedCost;

    /**
     * process type
     */
    @WhereType(filed = "process_id", type = WhereTypeEnum.NULL)
    private Boolean processIdIsNull;
    @WhereType(filed = "process_type", tableName = "main_line_process", orGroup = "workCode")
    private String processType;

    @WhereType(filed = "nick_name", tableName = "a", type = WhereTypeEnum.LIKE)
    private String projectManager;

    public void setProcessType(String processType) {
        this.processType = processType;
        if ("XL".equals(processType)) {
            this.workCodePb = "PB";
            this.workCodeJq = "JQ";
        } else if ("null".equals(processType)) {
            this.processTypeNull = true;
            this.processType = null;
            this.workCodeNotPb = "PB";
            this.workCodeNotJq = "JQ";
        }
    }

    @WhereType(tableName = "main_line_process", filed = "process_type", type = WhereTypeEnum.NULL)
    private Boolean processTypeNull;
    @WhereType(tableName = "main_line_process", filed = "process_type_name", type = WhereTypeEnum.NULL)
    private Boolean processTypeNameNull;

    @WhereType(filed = "process_type_name", func = "IFNULL( main_line_process.process_type_name, IF ( main_process_order.work_code LIKE '%PB%' OR main_process_order.work_code LIKE '%JQ%', '下料工序', '其它' ) ) ={1}")
    private String processTypeName;

    @WhereType(filed = "process_type_name")
    private String processTypeNameNew;

    public void setProcessTypeName(String processTypeName) {
        this.processTypeName = processTypeName;
        if ("其它".equals(processTypeName) || "null".equals(processTypeName)) {
            this.processTypeNameNull = true;
            this.processTypeName = null;
            this.workCodeNotPb = "PB";
            this.workCodeNotJq = "JQ";
        }
    }

    @WhereType(func = "main_process_order_check.check_content ->> '$[0].itemList[0].checkVal' > 1")
    private Boolean isQtException;

    @WhereType(filed = "nick_name", tableName = "sys_user")
    private String projectNickName;
    @WhereType(filed = "user_id", tableName = "main_project")
    private Long projectUserId;

    @WhereType(filed = "work_code", orGroup = "workCode", type = WhereTypeEnum.LIKE)
    private String workCodePb;
    @WhereType(filed = "work_code", orGroup = "workCode", type = WhereTypeEnum.LIKE)
    private String workCodeJq;

    @WhereType(filed = "work_code", type = WhereTypeEnum.NOT_LIKE)
    private String workCodeNotPb;
    @WhereType(filed = "work_code", type = WhereTypeEnum.NOT_LIKE)
    private String workCodeNotJq;

    @WhereType(func = " date_format(work_start_time, '%Y-%m-%d') = {1} ")
    private String workStartTimeFormat;

    @WhereType(ignore = true)
    private Boolean isDelay;

    @WhereType(ignore = true)
    private String startTime;

    @WhereType(ignore = true)
    private String endTime;


    @WhereType(filed = "is_del", tableName = "main_process_order_users")
    private Boolean wuIsDel;

    @WhereType(filed = "dept_id", func = " sys_dept.dept_id IN ( SELECT p.dept_id FROM sys_dept p WHERE p.dept_id = {1} or find_in_set( {1} , p.ancestors ) )")
    private Long deptId;

    @WhereType(filed = "status", tableName = "main_project", type = WhereTypeEnum.NOTIN)
    private List<Integer> projectStatusNotIn;

    private String dateType;

    @WhereType(filed = "project_machine_no", tableName = "main_project", type = WhereTypeEnum.LIKE)
    private String projectMachineNo;

    private List<String> costMonthBetween;

    @WhereType(ignore = true)
    private String deptName;

    @WhereType(ignore = true)
    private String yearMonth;

    private String month;

    @WhereType(ignore = true)
    private String queryType;

    private String costFactory;

    private String processTypeNameBudget;

    // 车间名
    @WhereType(filed = "factory_name", tableName = "sys_dept")
    private String deptFactoryName;

    @WhereType(filed = "customer_name", tableName = "main_project")
    private String customerName;

    // 员工工时处理
    @WhereType(ignore = true)
    private String queryFrom;

    @WhereType(ignore = true)
    private String ym;

    @WhereType(filed = "order_type")
    private Integer orderType;

    @WhereType(filed = "assigned_cost", func = "IFNULL(assigned_cost,0)=0")
    private Boolean noAssignedCost;

    @WhereType(filed = "work_cost", func = "IFNULL(main_process_order.work_cost,0)>0")
    private Boolean workCostMoreThanOne;

    @WhereType(ignore = true)
    private String workTypeStr;
}
